<template>
  <div class="login">
    <div class="login_box">
      <!-- 头像 -->
      <div class="login_img">
        <img src="../assets/logo.png" />
      </div>
      <!-- 登录 -->
      <el-form
        label-width="0px"
        class="login_form"
        :model="form"
        :rules="rules"
        ref="longin_formref"
      >
        <!-- 账号 -->
        <el-form-item prop="username">
          <el-input
            prefix-icon="el-icon-s-custom"
            v-model="form.username"
            placeholder="请输入账号"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            type="password"
            prefix-icon="el-icon-s-opportunity"
            v-model="form.password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item class="btns">
          <el-button type="primary" @click="login">登录</el-button>
          <el-button type="info" @click="rest">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import {
// 	login
// } from '../network/base.js'

import { request1, request2 } from "../api/api.js";

export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
        type: 1,
      },
      rules: {
        username: [
          {
            required: true,
            message: "账号不能为空",
            trigger: "blur",
          },
          {
            min: 3,
            max: 11,
            message: "长度在 3 到 11 个字符",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "密码不能为空",
            trigger: "blur",
          },
          {
            min: 3,
            max: 16,
            message: "长度在 3 到 16 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    // request1({
    // 	methods:"get",
    // 	url:"/mine/getResumeCheck?username="+15270292765,
    // }).then(res=>{
    // 	console.log(res)
    // })
  },

  // created() {
  // 	// 接口1
  // 	request1({
  // 		// methods:"get",
  // 		url: "/web/findByTrainingFactoryAll"
  // 	}).then(res => {
  // 		console.log(res)
  // 	})
  // 	//接口2
  // 	request2({
  // 		// methods:"get",
  // 		url: "/company/list"
  // 	}).then(res => {
  // 		console.log(res)
  // 	})
  // },

  methods: {
    //登录
    login() {
      this.$refs.longin_formref.validate(async (valid) => {
        if (valid) {
          this.$router.replace("/index");

          console.log(this.form.username, this.form.password);

          request1({
            method: "post",
            url: "user/login",
            // data:{
            //   phone:this.form.username,
            //   password:this.form.password
            // }
            data: this.form,
          })
            .then((res) => {
              if (res.code == 200) {
                this.$message.success(res.msg);
                localStorage.setItem("token", res.token);
                this.$router.replace("/index");
              } else {
                this.$message.error(res.msg)
              }

              // console.log("成功", res);
            })
            .catch((err) => {
              console.log("请求失败", err);
            });
          // const result = await login(this.form)
          //把result重命名为data：res
          // const {data:res} = await login(this.form)
          // console.log(res)
          // if (result.code == 200) {
          // 	this.$message.success("登陆成功")
          // 	localStorage.setItem('token', result.data)
          // 	this.$router.replace('/index')
          // } else {
          // 	return this.$message.error("账号或密码错误")
          // }
          // console.log(result)
        } else {
          console.log("不能提交");
          return false;
        }
        // console.log(valid)
      });
    },
    //重置
    rest() {
      // console.log(11);
      this.form.username = ""
      this.form.password = ""
      this.$refs.longin_formref.resetFields();
    },
  },
};
</script>

<style  scoped>
.login {
  height: 100%;
  background-color: skyblue;

  /* // display: flex;
  // justify-content: center;
  // align-items: center; */
}
.login_box {
  width: 450px;
  height: 300px;
  background-color: #ffffff;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.login_img {
  width: 130px;
  height: 130px;
  border: 1px solid #eeeeee;
  border-radius: 50%;
  /* // padding: 10px; */
  background-color: #eeeeee;
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);

  display: flex;
  justify-content: center;
  align-items: center;
}
.login_img > img {
  width: 70%;
  height: 70%;
}
.login_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 20px;
  box-sizing: border-box;
}
.btns {
  display: flex;
  justify-content: center;
}
.btns > button:nth-child(1) {
  margin-right: 40px;
}
</style>
